﻿using System;
using System.Collections;
using System.Data;
using ZhongLangDB;

namespace ZHONGLANGWEBUI
{
    public partial class Index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            { 
                if (TT_BasePage.CURREMP.USERID == "") { Response.Redirect("LOGIN.aspx"); } 

                this.Title = hidPowerName.Value;
                spanXTMC.InnerHtml = hidSysName.Value;
                lb_UserName.Text = TT_BasePage.CURREMP.USERNAME;

                SortedList SDList = new SortedList();
                SDList["KEYID"] = TT_BasePage.CURREMP.USERID;
                DataTable dt = DBPark.proGetDT(SDList, "PROTT_SYS_USERQUERY"); 
                DataRow dr = dt.Rows[0];

                spanZDY.InnerHtml = dr["USERSELFMSG"].ToString(); 
                userImg.Attributes["src"] = dr["USERHEAD"].ToString();
                imgLogoCom.Attributes["src"] = dr["COMICON"].ToString();
                lblComName.InnerText = dr["COMNAME"].ToString();
                pageBind();
            }
        }

        #region pageBind
        protected string pageBindHref(DataRow dr) {
            string strPath = dr["MENUPATH"].ToString();
            string strTemp = (strPath.IndexOf('?') > 0 ? "&" : "?");
            string strTitle = "";// "&TITLE=" + dr["MENUTITLE"].ToString();
            string strPageCount = "&PAGECOUNT=" + dr["PAGECOUNT"].ToString();
            string strRand = "&RANDNO=" + Guid.NewGuid().ToString().Substring(0, 8);
            strPath = strPath + strTemp + strTitle + strPageCount + strRand;

            strPath = "<a class = 'J_menuItem' href = '" + strPath + "' target='iframeRight'>"
                    + (dr["MENUIMGCSS"].ToString() == "" ? "" : "<i class='" + dr["MENUIMGCSS"].ToString() + "'></i>")
                    + dr["MENUNAME"].ToString() + "</a>";
            return strPath;            
        }
        protected void pageBind()
        {
            DataTable dtMenu = DBPark.proGetDT(null,"SELECT * FROM TT_SYS_MENU");
            string strTest = System.Configuration.ConfigurationManager.AppSettings["ZHONGLANG_TEST"].ToString();
            strTest = (strTest != "1" ? " AND '" + TT_BasePage.CURREMP.ROLEMENU + "' LIKE '%'+MENUID+'%' " : "");
            DataRow[] dt1 = dtMenu.Select("MENUPRO = 'TT'" + strTest, "MENUORDER");
            string temp2 = "",temp3 = ""; divShow.InnerHtml = "";
            for (int i = 0; i < dt1.Length; i++) //1级菜单
            {
                DataRow[] dt2 = dtMenu.Select("MENUPRO = '" + dt1[i]["MENUID"].ToString() + "' " + strTest, "MENUORDER");
                if (dt2.Length == 0) { continue; }temp2 = "";
                for (int j = 0; j < dt2.Length; j++) //2级菜单
                {
                    DataRow[] dt3 = dtMenu.Select("MENUPRO = '" + dt2[j]["MENUID"].ToString() + "' " + strTest, "MENUORDER");
                    if (dt3.Length == 0) { continue; } temp3 = "";
                    for (int k = 0; k < dt3.Length; k++) {  temp3 += "<li>" + pageBindHref(dt3[k]) + "</li>";  }
                    temp2 += "<li><a href='#'><i class='" + dt2[j]["MENUIMGCSS"].ToString() + " '></i>" +  dt2[j]["MENUNAME"].ToString() + "<span class='fa arrow'></span></a>" 
                          + "<ul class='nav nav-third-level'>" + temp3 + "</ul></li>"; 
                }
                divShow.InnerHtml += "<li><a href='#'><i class='" + dt1[i]["MENUIMGCSS"].ToString() + " '></i><span class='nav-label'>" + dt1[i]["MENUNAME"].ToString() + "</span><span class='fa arrow'></span></a>"
                                  + "<ul class='nav nav-second-level'>" + temp2 + "</ul></li>";
            }
        }
        #endregion
    }
}